-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(google): add media resolution option #8490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good so far. Can you please go through the task list in the pull request description? In particular, please add a test and manually verify that the change is working (we usually do that by updating one of the existing examples in examples/ai-core/
@gr2m a new test has been added, and I've manually verified the functionality. |
I tried to get different results with the |
@gr2m It affects the number of tokens used by the model. In my case, we've uploaded a 2hr video to Gemini and it went over the limit until I used a low media resolution (https://ai.google.dev/api/generate-content#MediaResolution) |
@gr2m example: import { google } from '@ai-sdk/google';
import { generateText } from 'ai';
import 'dotenv/config';
async function main() {
const videoUrl =
'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4';
const resultWithMediaLow = await generateText({
model: google('gemini-2.5-flash'),
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: `Summarize the video.`,
},
{
type: 'file',
data: videoUrl,
mediaType: 'video/mp4',
},
],
},
],
providerOptions: {
google: {
mediaResolution: 'MEDIA_RESOLUTION_LOW',
},
},
});
console.log(
"Token usage with 'MEDIA_RESOLUTION_LOW':",
resultWithMediaLow.totalUsage.totalTokens,
);
const resultWithoutMedia = await generateText({
model: google('gemini-2.5-flash'),
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: `Summarize the video.`,
},
{
type: 'file',
data: videoUrl,
mediaType: 'video/mp4',
},
],
},
],
});
console.log(
"Token usage without 'mediaResolution':",
resultWithoutMedia.totalUsage.totalTokens,
);
}
main().catch(console.error); Output:
|
Background
I was looking to add mediaResolution and found #6256 pull request. It seems to have been inactive for some time, so I've opened this PR that specifically addresses the addition of mediaResolution.
Summary
Pass mediaResolution to google provider options
Manual Verification
Tasks
pnpm changeset
in the project root)pnpm prettier-fix
in the project root)Related Issues
closes #6256